package com.woniu.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.PageResult;
import com.woniu.user.mapper.CarParamsMapper;
import com.woniu.user.pojo.CarParams;
import com.woniu.user.pojo.dto.SearchCarParamDTO;
import com.woniu.user.service.ICarParamsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 车辆参数表 服务实现类
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
@Service
public class CarParamsServiceImpl extends ServiceImpl<CarParamsMapper, CarParams> implements ICarParamsService {

    @Autowired
    private CarParamsMapper carParamsMapper;

    @Override
    public PageResult<CarParams> listOrSearchPage(Integer currentPage, Integer pageSize, SearchCarParamDTO searchCarParamDTO) {
        IPage<CarParams> page = new Page<>(currentPage, pageSize);
        LambdaQueryWrapper<CarParams> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(!StringUtils.isEmpty(searchCarParamDTO.getCarName()), CarParams::getCarName, searchCarParamDTO.getCarName());
        wrapper.like(!StringUtils.isEmpty(searchCarParamDTO.getTypeName()), CarParams::getTypeName, searchCarParamDTO.getTypeName());
        wrapper.like(!StringUtils.isEmpty(searchCarParamDTO.getStyle()), CarParams::getStyle, searchCarParamDTO.getStyle());
        IPage<CarParams> pages = carParamsMapper.selectPage(page, wrapper);
        return new PageResult<>(pages.getTotal(), pages.getRecords());
    }
}
